import {Directive, ElementRef, HostListener, Input, OnInit} from '@angular/core';
import {AppComponent} from "../../../app.component";
import {AppService} from "../../../app.service";
import {GlobalEvent} from "../../../support/event.definition";

@Directive({
  selector: '[ss-platform-tip]'
})
export class TipDirective implements OnInit {

  @Input("ss-platform-tip")
  message: string;
  element: HTMLElement;

  constructor(private elementRef: ElementRef, private $app: AppService) {
  }

  ngOnInit(): void {
    this.element = this.elementRef.nativeElement;
  }

  @HostListener("mouseenter", ["$event"])
  enter($event): void {
    this.$app.publish(GlobalEvent.ShowTip, this.message, this.element);
  }

  @HostListener("mouseleave", ["$event"])
  leave($event): void {
    this.$app.publish(GlobalEvent.HideTip);
  }

}
